chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
    if (request.title) {
        $.post("http://127.0.0.1:5000/scrapy", {
            "product": JSON.stringify({
                "favcount": request.favcount,
                "shopName": request.shopName,
                "title": request.title,
                "data": request.data
            })
        });
    }

    // 查询发送信息的tab,及时关闭tab
    chrome.tabs.query({
        url: sender.url
    }, function (tabs) {
        if (tabs.length) {
            chrome.tabs.remove(tabs[0].id);
        }
    });

    // 查询list页，告知其继续点击宝贝进行抓取
    chrome.tabs.query({
        url: 'https://boxandneedle.taobao.com/*'
    }, function (tabs) {
        if (tabs.length) {
            chrome.tabs.sendMessage(tabs[0].id, {
                "name": "scrapy next"
            }, function (response) {

            });
        }
    });
});

chrome.devtools.network.onRequestFinished.addListener(
    function (request) {
        if (request.response.bodySize > 5 * 1024) {
            chrome.devtools.inspectedWindow.eval(
                'console.log("Large image: " + unescape("' +
                escape(request.request.url) + '"))');
        }
    });